package com.alibaba.nacos.config.server.jpa.entity;

import java.time.LocalDateTime;
import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.springframework.data.annotation.LastModifiedDate;

/**
 * @author
 * @date 2020-03-08 23:31
 * 增加租户字段
 */
@Entity
@Table(name = "NACOS_CONFIG_INFO_AGGR", uniqueConstraints = {
    @UniqueConstraint(name = "UK_CONFIGINFOAGGR_DATAGROUPTENANTDATUM",
        columnNames = {"DATA_ID","GROUP_ID","TENANT_ID","DATUM_ID"})
})
public class ConfigInfoAggrEntity extends AbstractEntity {

    private static final long serialVersionUID = 1L;

    public ConfigInfoAggrEntity () {}



    @Column(name = "APP_NAME")
    private String appName;

    /**
     * 内容
     */
    @Column(name = "CONTENT", nullable = false)
    @Lob
    private String content;

    /**
     * data_id
     */
    @Column(name = "DATA_ID", nullable = false)
    private String dataId;

    /**
     * datum_id
     */
    @Column(name = "DATUM_ID", nullable = false)
    private String datumId;

    /**
     * 修改时间
     */
    @Column(name = "GMT_MODIFIED", nullable = false)
    @LastModifiedDate
    private LocalDateTime gmtModified;

    /**
     * group_id
     */
    @Column(name = "GROUP_ID", nullable = false)
    private String groupId;

    /**
     * 租户字段
     */
    @Column(name = "TENANT_ID")
    private String tenantId;


    public ConfigInfoAggrEntity setAppName(String appName){
        this.appName = appName;
        return this;
    }

    public String getAppName(){
        return appName;
    }

    public ConfigInfoAggrEntity setContent(String content){
        this.content = content;
        return this;
    }

    public String getContent(){
        return content;
    }

    public ConfigInfoAggrEntity setDataId(String dataId){
        this.dataId = dataId;
        return this;
    }

    public String getDataId(){
        return dataId;
    }

    public ConfigInfoAggrEntity setDatumId(String datumId){
        this.datumId = datumId;
        return this;
    }

    public String getDatumId(){
        return datumId;
    }

    public ConfigInfoAggrEntity setGmtModified(LocalDateTime gmtModified){
        this.gmtModified = gmtModified;
        return this;
    }

    public LocalDateTime getGmtModified(){
        return gmtModified;
    }

    public ConfigInfoAggrEntity setGroupId(String groupId){
        this.groupId = groupId;
        return this;
    }

    public String getGroupId(){
        return groupId;
    }

    public ConfigInfoAggrEntity setTenantId(String tenantId){
        this.tenantId = tenantId;
        return this;
    }

    public String getTenantId(){
        return tenantId;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("ConfigInfoAggrEntity = {");

        if (appName != null){
            sb.append("appName = ").append(appName).append(", ");
        }
        if (content != null){
            sb.append("content = ").append(content).append(", ");
        }
        if (dataId != null){
            sb.append("dataId = ").append(dataId).append(", ");
        }
        if (datumId != null){
            sb.append("datumId = ").append(datumId).append(", ");
        }
        if (gmtModified != null){
            sb.append("gmtModified = ").append(gmtModified).append(", ");
        }
        if (groupId != null){
            sb.append("groupId = ").append(groupId).append(", ");
        }
        if (id != null){
            sb.append("id = ").append(id).append(", ");
        }
        if (tenantId != null){
            sb.append("tenantId = ").append(tenantId);
        }

        sb.append("}");
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ConfigInfoAggrEntity entity = (ConfigInfoAggrEntity) o;
        return Objects.equals(dataId, entity.dataId) &&
            Objects.equals(groupId, entity.groupId) &&
            Objects.equals(tenantId, entity.tenantId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(dataId, groupId, tenantId);
    }
}
